﻿

//

using BootstrapBlazor.Components;
using LaserMark.Models;

namespace LaserMark.Extensions;
public static class CalcPointByPositionExtension
{
    public static (double x, double y) Calc(MarkPoint item, int xoffset, int yoffset, int width, int height)
    {
        // opt 默认为右上角点位
        var x = item.X;
        var y = item.Y;
        if (item.Type == "G")
        {
            if (item.BasicEdge != item.SheetWidth)
            {
                if (item.Position == Position.RightTop)
                {
                    x = item.X + xoffset + width / 2;
                    y = item.Y + yoffset + height / 2;
                }
                else if (item.Position == Position.RightBottom)
                {
                    x = item.X + xoffset + width / 2;
                    y = item.Y + item.SheetWidth - yoffset - height / 2;
                }
                else if (item.Position == Position.LeftTop)
                {
                    y = item.Y + yoffset + height / 2;
                    x = item.X + item.SheetHeight - xoffset - width / 2;
                }
                else if (item.Position == Position.LeftBottom)
                {
                    x = item.X + item.SheetHeight - xoffset - width / 2;
                    y = item.Y + item.SheetWidth - yoffset - height / 2;
                }
            }
            else
            {
                if (item.Position == Position.RightTop)
                {
                    x = item.X + item.SheetHeight - xoffset - height / 2;
                    y = item.Y + yoffset + width / 2;
                }
                else if (item.Position == Position.RightBottom)
                {
                    x = item.X + xoffset + height / 2;
                    y = item.Y + yoffset + width / 2;
                }
                else if (item.Position == Position.LeftTop)
                {
                    y = item.Y + item.SheetWidth - yoffset - width / 2;
                    x = item.X + item.SheetHeight - xoffset - height / 2;
                }
                else if (item.Position == Position.LeftBottom)
                {
                    x = item.X + xoffset + height / 2;
                    y = item.Y + item.SheetWidth - yoffset - width / 2;
                }
            }
        }
        else
        {
            if (item.Position == Position.LeftBottom)
            {
                if (item.SheetWidth - item.SheetHeight > 0)
                {
                    x = item.X - item.SheetHeight;
                    y = item.Y - item.SheetWidth;
                }
                else
                {
                    x = item.X - item.SheetWidth;
                    y = item.Y - item.SheetHeight;
                }
            }
            else if (item.Position == Position.RightBottom)
            {
                if (item.SheetWidth - item.SheetHeight > 0)
                {
                    y = item.Y - item.SheetWidth;
                }
                else
                {
                    y = item.Y - item.SheetHeight;
                }
            }
            else if (item.Position == Position.LeftTop)
            {
                if (item.SheetWidth - item.SheetHeight > 0)
                {
                    x = item.X - item.SheetHeight;
                }
                else
                {
                    x = item.X - item.SheetWidth;
                }
            }
        }
        return (x, y);
    }
}
